//
//  UIImageView+ZCHelp.m
//  UniversalApp
//
//  Created by 凯朱 on 2019/7/2.
//  Copyright © 2019 徐阳. All rights reserved.
//

#import "UIImageView+ZCHelp.h"

@implementation UIImageView (ZCHelp)
#pragma mark - ————— 图片设置 —————

/**
 设置图片
 */
-(void)zc_setImageWithUrlStr:(NSString *)urlStr{
     NSString *url = kSTRING(urlStr);
    if (url.length == 0) {
        self.image = kDefaultImage;
        return;
    }
    NSString *imageUrl = @"";
    if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"]) {
        imageUrl = url;
    }else{
        imageUrl = [NSString stringWithFormat:@"%@/%@",URL_image,urlStr];
    }
    [self sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:kDefaultImage];
}

/**
 让一个图片进行360度旋转
 */
-(void)rotate360Degree{
    CABasicAnimation *animation = [ CABasicAnimation
                                   animationWithKeyPath: @"transform"];
    animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    
    //围绕Z轴旋转，垂直与屏幕
    animation.toValue = [ NSValue valueWithCATransform3D:
                         
                         CATransform3DMakeRotation(M_PI/2, 0.0, 0.0, 1.0) ];
    animation.duration = 0.25;
    //旋转效果累计，先转180度，接着再旋转180度，从而实现360旋转   此处是90度旋转   可以实现顺时针旋转
    animation.cumulative = YES;
    animation.repeatCount = 1000;
    animation.removedOnCompletion = NO;
    
    [self.layer addAnimation:animation forKey:nil];
}

/**
 让一个图片进行360度旋转
 */
-(void)rotate360Degree:(CGFloat)durtion{
    CABasicAnimation *animation = [ CABasicAnimation
                                   animationWithKeyPath: @"transform"];
    animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    
    //围绕Z轴旋转，垂直与屏幕
    animation.toValue = [ NSValue valueWithCATransform3D:
                         
                         CATransform3DMakeRotation(M_PI/2, 0.0, 0.0, 1.0) ];
    animation.duration = durtion;
    //旋转效果累计，先转180度，接着再旋转180度，从而实现360旋转   此处是90度旋转   可以实现顺时针旋转
    animation.cumulative = YES;
    animation.repeatCount = 1000;
    animation.removedOnCompletion = NO;
    
    [self.layer addAnimation:animation forKey:nil];
}
@end
